package com.ruoyi.driver.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.driver.domain.CarownerMiddle;
import com.ruoyi.driver.service.ICarownerMiddleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆和路线中间Controller
 * 
 * @author Wevon
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/driver/middle")
public class CarownerMiddleController extends BaseController
{
    @Autowired
    private ICarownerMiddleService carownerMiddleService;

    /**
     * 查询车辆和路线中间列表
     */
    @PreAuthorize("@ss.hasPermi('driver:middle:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerMiddle carownerMiddle)
    {
        startPage();
        List<CarownerMiddle> list = carownerMiddleService.selectCarownerMiddleList(carownerMiddle);
        return getDataTable(list);
    }

    /**
     * 导出车辆和路线中间列表0
     */
    @PreAuthorize("@ss.hasPermi('driver:middle:export')")
    @Log(title = "车辆和路线中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerMiddle carownerMiddle)
    {
        List<CarownerMiddle> list = carownerMiddleService.selectCarownerMiddleList(carownerMiddle);
        ExcelUtil<CarownerMiddle> util = new ExcelUtil<CarownerMiddle>(CarownerMiddle.class);
        util.exportExcel(response, list, "车辆和路线中间数据");
    }

    /**
     * 获取车辆和路线中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('driver:middle:query')")
    @GetMapping(value = "/{carDetialsId}")
    public AjaxResult getInfo(@PathVariable("carDetialsId") Long carDetialsId)
    {
        return success(carownerMiddleService.selectCarownerMiddleByCarDetialsId(carDetialsId));
    }

    /*根据车主ID查询路线*/
    @GetMapping("/ByCaOwnerId/{carOwnerId}")
    public AjaxResult selectByCarOwnerId(@PathVariable("carOwnerId") Long carOwnerId){
        return success(carownerMiddleService.selectByCarOwnerId(carOwnerId));
    }

    /**
     * 新增车辆和路线中间
     */
    @PreAuthorize("@ss.hasPermi('driver:middle:add')")
    @Log(title = "车辆和路线中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerMiddle carownerMiddle)
    {
        return toAjax(carownerMiddleService.insertCarownerMiddle(carownerMiddle));
    }

    /**
     * 修改车辆和路线中间
     */
    @PreAuthorize("@ss.hasPermi('driver:middle:edit')")
    @Log(title = "车辆和路线中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerMiddle carownerMiddle)
    {
        return toAjax(carownerMiddleService.updateCarownerMiddle(carownerMiddle));
    }

    /**
     * 删除车辆和路线中间
     */
    @PreAuthorize("@ss.hasPermi('driver:middle:remove')")
    @Log(title = "车辆和路线中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carDetialsIds}")
    public AjaxResult remove(@PathVariable Long[] carDetialsIds)
    {
        return toAjax(carownerMiddleService.deleteCarownerMiddleByCarDetialsIds(carDetialsIds));
    }
}
